(ns pe.p45
  (:use pe.triangles))

(def triangles (nthnext (tr-seq) 285))

(defn -p45 [at ap ah]
  (loop [t at p ap h ah]
  (let [tr (triangle t) pe (pentag p) he (hex h)]
    (do (println t p h tr pe he)
    (cond
      (> t 100000) "Out of bounds"
      (= tr pe he) tr
      (and (> pe tr) (> he tr)) (recur (inc t) p h)
      (and (< pe tr) (< he tr)) (recur t (inc p) (inc h))
      (and (< pe tr) (> he tr)) (recur (inc t) (inc p) h)
      (and (> pe tr) (< he tr)) (recur (inc t) p (inc h))
      (and (= tr pe) (< he tr)) (recur t p (inc h))
      (and (= tr he) (< pe tr)) (recur t (inc p) h)
      (and (= tr pe) (> he tr)) (recur (int t) (inc p) h)
      (and (= tr he) (> pe tr)) (recur (inc t) p (inc h))
      :else "FAIL"
    )))))

(println (-p45 286 165 143))